import { Node } from 'cc';
import { ecs } from 'db://app-game/libs/ecs/ECS';
import { UIID } from '../../../common/config/GameUIConfig';
import { Load } from '../load/Load';
import { SceneEntity } from '../SceneEntity';
import { HomeViewComp } from './view/HomeViewComp';

/** 首页 */
@ecs.register('Home')
export class Home extends SceneEntity {
  init() {}
  initLayout(): void {}
  /** 跳转到首页 */
  goto() {
    const load = ecs.getEntity<Load>(Load);
    load.loadRes(
      this,
      UIID.Home,
      [{ text: '正在加载游戏资源...', path: 'images' }],
      this.jumpCompleted.bind(this)
    );
  }

  /** 加载跳转完成 */
  jumpCompleted(node: Node) {
    this.add(node.getComponent(HomeViewComp)!);
  }
}
